<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
	</body>
	<script>
		
		function Person(id,name,sex) {
			this.id = id;
			this.name = name;
			this.sex = sex;
			
			// 属性函数可被继承
			this.desc = function(){
				console.log(this.name)
			}
			
		}
		
		// 原型函数不可被继承
		Person.prototype.getId = function() {
			console.log(this.id);
		}
		Person.prototype.getName = function() {
			console.log(this.name);
		}
		
		let person = new Person(1,'mrc',1);
		person.getId();
		person.desc();
		
		// 继承父类 Person
		function Teacher(id,name,sex,title) {
			Person.call(this,id,name,sex);
			this.title = title;
		}
		let teacher = new Teacher(2,'teacher',2,'english');
		
		// 继承了Person 内定义的方法
		teacher.desc();
		// teacher.getId(); is not a function
		
		// Person 就是Person函数对象所持有的prototype属性的构造器
		console.log(Person===Person.prototype.constructor)
		
		// 永远使用父类的prototype来创造子类的prototype，这样才不会打乱类继承结构。
		Teacher.prototype = Object.create(Person.prototype);
		
		let teacher2 = new Teacher(3,'test',1,'test');
		teacher2.getId();
	</script>
</html>
